﻿//TOP
Object.extend = function(dest, source, replace)
{
    for(prop in source)
    {
        if(replace == false && dest[prop] != null) continue;
        dest[prop] = source[prop];
    }
    return dest;
};
Object.extend(Function.prototype,
{
getArguments: function()
{
    var args = [];
    for(var i=0; i<this.arguments.length; i++)args.push(this.arguments[i]);
    return args;
}
,apply: function(o, a)
{
    var r, x = "__fapply";
    if(typeof o != "object") o =
    {
    };
    o[x] = this;
    var s = "r = o." + x + "(";
    for(var i=0; i<a.length; i++)
    {
        if(i>0) s += ",";
        s += "a[" + i + "]";
    }
    s += ");";
    eval(s);
    delete o[x];
    return r;
}
,bind: function(o)//
{
    if(!window.__objs)
    {
        window.__objs = [];
        window.__funcs = [];
    }
    var objId = o.__oid;
    if(!objId)__objs[objId = o.__oid = __objs.length] = o;
    var me = this;
    var funcId = me.__fid;
    if(!funcId)__funcs[funcId = me.__fid = __funcs.length] = me;
    if(!o.__closures)o.__closures = [];
    var closure = o.__closures[funcId];
    if(closure)return closure;
    o = null;
    me = null;
return __objs[objId].__closures[funcId] = function()
{
    return __funcs[funcId].apply(__objs[objId], arguments);
};
}
,bindAsEventListener:function(o)
{
if(!window.__objs)
{
    window.__objs = [];
    window.__funcs = [];
}
var objId = o.__oid;
if(!objId)__objs[objId = o.__oid = __objs.length] = o;
var me = this;
var funcId = me.__fid;
if(!funcId)__funcs[funcId = me.__fid = __funcs.length] = me;
if(!o.__closures)o.__closures = [];
var closure = o.__closures[funcId];
if(closure)return closure;
o = null;
me = null;
return __objs[objId].__closures[funcId] = function(event)
{
    return __funcs[funcId].apply(__objs[objId], [event || window.event]);
};
}
}
, false);
Object.extend(String.prototype,
{
trimLeft: function()
{
    return this.replace(/^\s*/,"");
}
,trimRight: function()
{
    return this.replace(/\s*$/,"");
}
,trim: function()
{
    return this.trimRight().trimLeft();
}
}
, false);
Object.extend(Array.prototype,
{
push: function(o)
{
    this[this.length] = o;
}
,clear: function()
{
    this.length = 0;
    return this;
}
,shift: function()
{
    if(this.length == 0) return null;
    var o = this[0];
    for(var i=0; i<this.length-1; i++)this[i] = this[i + 1];
    this.length--;
    return o;
}
}
, false);
Object.extend(window,
{
$: function()
{
    var elements = new Array();
    for(var i=0; i<arguments.length; i++)
    {
        var e = arguments[i];
        if(typeof e == 'string')e = document.getElementById(e);
        if (arguments.length == 1)return e;
        elements.push(e);
    }
    return elements;
}
    ,Class:
    {
        create: function()
        {
            return function()
            {
                if(typeof this.initialize == "function")this.initialize.apply(this, arguments);
            }
        }
    }
}
, false);